package com.example.exception;

import cn.dev33.satoken.util.SaResult;
import com.example.utils.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice("com.example.controller")
public class GlobalExceptionHandler {
    // 全局异常拦截
    @ExceptionHandler
    public SaResult handlerException(Exception e) {
        e.printStackTrace();
        return SaResult.error(e.getMessage());
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody//返回json串
    public Result customError(CustomException e) {
        return Result.error(e.getCode(), e.getMsg());
    }


}
